package com.ruoyi.goods.utils;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class AliPayConfig implements ApplicationRunner {
    // 支付宝网关
    public static String gatewayUrl = "openapi.alipay.com";

    private Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipay.com";
        config.signType = "RSA2";
        config.appId = "2021002110676035".trim(); // 2016110100783053
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCdi6Ux2XaFd0vxDNoCA7WnPEhM/vurrVBP5njPZGKe3g3b74y/qtJFGgMskbsIlacAB/FdXT50DY3+cLmJY0fTwqnG4Are4G5BdkV4k5zDt0TlGhlxuwaFOU7E0vgd4CjO6Ri8g1H75/F68KWkML6eGIqIRt8Iy7bq902C02hrwSMULSZEd0+fYHREFTzjfucHI2DPr9bWg7slMtxyHWGGhSkeLXTnBRVP3iwWWDMpnlcHT1rRRm3wb/3M1Aa9bXSSE+JDLmRj0RpVLuKJsYAj4at3jHZhW5yNQqamAAQx4PcSLKrEKb73x2VqdurAi3dF0G5TZVZuqvurrr7LhCIFAgMBAAECggEADr2mM0fZoxtKa798FnwqXv9w9GNXQPTycsdpvl3yLFMykMWVMcnV6slISr9H9MGr4oDbwJSc51btVkVN1uEHM3UfVZBY9Amjx1Q9o86L+HQJajZK8y1Aqu51xEzJEmKK7vE4c0sGPL+zBIHHvdkhvMEnFSEsdTI6ZznEct09A/fkZmkTeo6HX6XGHp61PZI3Zdbj10UY8rxmA/cFwB9eAHzNUos+4vJP/TqdcwAt5kCnmQ/rlGgrvBNWPVUPtFzoTP6HpiFKAxuJYHMVnqW+j6sHYtMU1dJUOoDZmnOZoLrm4VQM8FoKHmZcRRxOGzHYvrH6598W83VbEAExL0D48QKBgQDjJgWEx+XBxjBFtOExAyuKxNqfD2C6YVssNwEEeipLmIIWEHtzNAFf3utAPsgTxuUYhOXsNUhrS6UwWsTZgm4/p5Mpt9UV9IoOIt/vfETA+w6jczSaY3XiR1cR23OWDlCzC85oxFgFrWxu9cGi0wNWK9YbkZAO9osNAgUho6RqJwKBgQCxjmgC29ZxCOZ22dCGRTZDX+nVsz6R3E3EL5zQfVSFUex0cAfH/sd4Aco67d89V8Mvvgxj6HxAQPggvz05McloRTqOmgFLlEkIBbO6CRwJ6c053tVzwCUZbJ4Xk2QDwC5B2Cfj9y2iOiMTXiPc6AXgnp+UTtvXT4hdUntOpogJ8wKBgQCTxkyY0aN7qQAGmWJXjIRrRx4jlNGM74FtBmu3CfMyMwmOaTKnBBJQ2KmbpjxsAV1R0kPyo8d1ZkUVbDfceapX5yEqZtpN6kVWZQHiv6nLEom3dF+ogURT7a2LhIVx/eYqVWf3aKULLIP6vA85aqYlDWfBj7V0xpg34jSMafWwyQKBgCoT0GxVAsW40Tz7M2KOhmSDF1wwZTSV28wRaH00JlKN7pZNclqf809qRS2f75aO9M+cnz0R/FgRzXudNnoWZV+TgGQI9SOfGYuQJl6BCCcFREBhoX4T2/bhebmmkT4eThgGjLWGf0cBtgxB9AfG6JWpobG42np0+6D6CgTCjFynAoGAVKZDOpgcWyNbxW6ZpCh26JkL2AcDKvBuwrDqc3y1swUlbxE9BrLKw2vW/jqiLEw5zypb8r4IymyYATZj5uYP3b4lfDWgQJq7JTj3fKwwavHHi2JrVCtcBeTWr5Le6h3mhD8P86hdNbqA1ArwrlpjFsS6cn6WlS3dQZP5GxWZ1+Y=".trim();
        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm2jm0v5tCpCvQUVQz094eEZPZfEhK6CITP4sqSAaKXSrV6Ukl6Xn+4MRrFB5ge7BxdWc6DLM+F4xnjBrEglu5w10hu2s4mexNRjx5S5KJ1hJL0p6KXCIQqjW3m2I0Oq5zJfWwSUh4vo9ZyTKFj3U+HXWss6KHE58LUCLZDGa5YynT5YBunJpQFhfrZ1gdLykj5nNzmED2X2VibLapzctcLet6GqIkeweuL8LS/raM1SBurc3UkPzwvWcezWQLb6PAdQkPZ1a3DcTKpvTqO9GOh1e5LVgQVGq5XHs94VZVtYgduZXl4zamos2s+JDUP5ra6QSB9Dsf3lZZB8Eye+6FwIDAQAB".trim();
        return config;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Factory.setOptions(getOptions());
        System.out.println("**********支付宝SDK初始化完成**********");
    }
}
